import 'package:custom_widgets/custom_localizations.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

///性别选择弹出框
class SexPickerDialog extends StatelessWidget {
  SexPickerDialog({
    Key? key,
  }) : super(key: key);

  /// 性别选择弹出
  /// [return int] 1: 男, 0: 女
  static Future<int?> show(BuildContext context) {
    return showCupertinoModalPopup(
      context: context,
      builder: (BuildContext context) {
        return SexPickerDialog();
      },
    );
  }

  /// 默认语言
  final Custom_Localizations _localizations = Custom_Localizations();

  @override
  Widget build(BuildContext context) {
    /// 按钮高度
    const double _buttonHeight = 60.0;

    ///单个选项高度
    const double _spacing = 60.0;

    String manText = Custom_Localizations.current?.man ?? _localizations.man;

    String woManText =
        Custom_Localizations.current?.woMan ?? _localizations.woMan;

    String cancelText =
        Custom_Localizations.current?.cancel ?? _localizations.cancel;

    return SafeArea(
      child: Container(
        margin: const EdgeInsets.symmetric(
          horizontal: 10.0,
          vertical: 10.0,
        ),
        child: Column(
          mainAxisSize: MainAxisSize.min,
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: <Widget>[
            Container(
              height: _spacing,
              child: TextButton(
                style: ButtonStyle(
                  backgroundColor:
                      WidgetStateProperty.all(Theme.of(context).canvasColor),
                  overlayColor:
                      WidgetStateProperty.all(Theme.of(context).splashColor),
                  shape: WidgetStateProperty.all(
                    RoundedRectangleBorder(
                      borderRadius: BorderRadius.vertical(
                        top: Radius.circular(12.0),
                      ),
                    ),
                  ),
                ),
                child: Text(
                  manText,
                  style: Theme.of(context).textTheme.labelLarge,
                ),
                onPressed: () {
                  Navigator.pop(context, 1);
                },
              ),
            ),
            Divider(indent: 0.0),
            Container(
              height: _spacing,
              child: TextButton(
                style: ButtonStyle(
                  overlayColor:
                      WidgetStateProperty.all(Theme.of(context).splashColor),
                  backgroundColor:
                      WidgetStateProperty.all(Theme.of(context).canvasColor),
                  shape: WidgetStateProperty.all(
                    RoundedRectangleBorder(
                      borderRadius: BorderRadius.vertical(
                        bottom: Radius.circular(12.0),
                      ),
                    ),
                  ),
                ),
                child: Text(
                  woManText,
                  style: Theme.of(context).textTheme.labelLarge,
                ),
                onPressed: () {
                  Navigator.pop(context, 0);
                },
              ),
            ),
            SizedBox(height: 10.0),
            Container(
              height: _buttonHeight,
              child: TextButton(
                style: ButtonStyle(
                  backgroundColor:
                      WidgetStateProperty.all(Theme.of(context).canvasColor),
                  shape: WidgetStateProperty.all(
                    RoundedRectangleBorder(
                      borderRadius: BorderRadius.all(
                        Radius.circular(12.0),
                      ),
                    ),
                  ),
                ),
                child: Text(
                  cancelText,
                  style: Theme.of(context).textTheme.labelLarge,
                ),
                onPressed: () {
                  Navigator.pop(context, null);
                },
              ),
            ),
          ],
        ),
      ),
    );
  }
}
